// pages/content/content.js
import store from "../../store/index"
import create from "../../utils1/create"

create.Page(store, {
  use: ['isToken', "GroupInfo", "settjitems",'infouser'],
  data: {
    hidden: false,
    Begin_Year: "",
    End_Year: "",
    typeIndex: 0,
    animationData: {},
    name: "",
    id: "",
    newid:"0",
    selectArray: [{
        "id": "0",
        "text": "近1年",
        "selectdate": new Date()
      }, {
        "id": "1",
        "text": "近3年",
        "selectdate": new Date()
      }, {
        "id": "2",
        "text": "近5年",
        "selectdate": new Date()
      },
      {
        "id": "3",
        "text": "自定义",
        "selectdate": new Date()
      }
    ],
    phone: "17373023530",
    numList: [],
    numList1: [],
    Hospital: '医林医疗',
    Physical: "02208230124",
    Pson_Tel: "",
    state: "",
    isHidden: true
  },

  requestData(viewState, callback) {
    wx.request({
      url: this.store.data.globhttp + "GetReleaseCheckReports",
      method: 'POST',
      header: {
        'content-type': 'application/json',
        "content-type": "application/x-www-form-urlencoded"
      },
      data: JSON.stringify({
        User_Id: store.data.infouser.User_Id,
        Token_Code: store.data.isToken,
        Begin_Year: this.data.Begin_Year,
        End_Year: this.data.End_Year,
        View_State: viewState
      }),
      success: (res) => {
        // wx.showLoading({
        // },2000)
        if (res.data.RltCode == 1) {
          const dataList = JSON.parse(res.data.RltData);
          callback(dataList);
        } else if (res.data.RltCode == 0) {
          callback([]);
        } else if (res.data.RltCode == 13) {
          this.store.setToken("settjitems");
        }
      },
      fail: (err) => {
        console.error("Request failed:", err);
      }
    });
  },

  clickMe1(e) {
    console.log("e",e)
    this.data.Begin_Year = e.detail.Begin_Year;
    this.data.End_Year = e.detail.End_Year;
    store.data.settjitems.startdate = this.data.Begin_Year;
    store.data.settjitems.enddate = this.data.End_Year;
    this.setData({
      Begin_Year: this.data.Begin_Year,
      End_Year: this.data.End_Year
    });
    if (this.data.Begin_Year !== "" && this.data.End_Year !== "") {
      // wx.showLoading({
      // },2000)
      this.fetchData();
    }
  },

  clickMe(e) {
    console.log("e",e)
    this.data.name = e.detail.name;
    this.data.id = e.detail.id;
    this.data.Begin_Year = e.detail.Begin_Year;
    this.data.End_Year = e.detail.End_Year;
    this.data.hidden = e.detail.hidden;
    store.data.settjitems.startdate = this.data.Begin_Year;
    store.data.settjitems.enddate = this.data.End_Year;
    this.setData({
      name: this.data.name,
      id: this.data.id,
      Begin_Year: this.data.Begin_Year,
      End_Year: this.data.End_Year,
      hidden: this.data.hidden
    });
    if (this.data.id != "3") {
      this.fetchData();
    }
  },

  sendxg() {
    wx.showModal({
      title: '温馨提示',
      content: '即将跳转到手机号修改页面',
      success: (res) => {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/xgphone/xgphone?id=1',
          });
        }
      }
    });
  },

  sendbd() {
    wx.showModal({
      title: '提示',
      content: '即将跳转到手机号绑定页面',
      success: (res) => {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/xgphone/xgphone?id=0',
          });
        }
      }
    });
  },

  downPdf(e) {
    wx.showToast({
      title: '打开成功',
    })
   setTimeout(()=>{
    const url = e.currentTarget.dataset.reportUrl;
    const Check_No = e.currentTarget.dataset.reportCheck;
    wx.navigateTo({
      url: `/pages/web-pdf/web-pdf?url=${url}&Check_No=${Check_No}`,
    });
   },2000)
  },

  fetchData() {
    // wx.showLoading({
    // },2000)
    this.requestData(0, (dataList) => {
      this.data.numList = dataList;
      store.data.settjitems.numList = dataList;
      this.setData({ numList: dataList });
    });
    this.requestData(1, (dataList) => {
      this.data.numList1 = dataList;
      store.data.settjitems.numList1 = dataList;
      this.setData({ numList1: dataList });
    });
    setTimeout(() => {
      wx.hideLoading();
      wx.showToast({ icon: 'loading', title: '加载中', mask: true });
    }, 100);
  },

  request() {
    this.requestData(this.data.typeIndex, (dataList) => {
      if (this.data.typeIndex == 0) {
        this.data.numList = dataList;
        store.data.settjitems.numList = dataList;
        this.setData({ numList: dataList });
      } else if (this.data.typeIndex == 1) {
        this.data.numList1 = dataList;
        store.data.settjitems.numList1 = dataList;
        this.setData({ numList1: dataList });
      }
    });
  },

  request1() {
    this.requestData(this.data.typeIndex, (dataList) => {
      if (this.data.typeIndex == 0) {
        this.data.numList = dataList;
        store.data.settjitems.numList = dataList;
        this.setData({ numList: dataList });
      } else if (this.data.typeIndex == 1) {
        this.data.numList1 = dataList;
        store.data.settjitems.numList1 = dataList;
        this.setData({ numList1: dataList });
      }
    });
  },

  onLoad(options) {
    wx.showLoading({
    },2000)
    store.data.settjitems.View_State = this.data.typeIndex;
    this.fetchData();
    setTimeout(() => {
      this.setData({ isHidden: false });
    }, 500);
    this.setData({ Hospital: '999' });
    this.setData({ Pson_Tel: store.data.infouser.Pson_Tel });
  },

  onReady() {},

  onShow() {
    // this.fetchData();
    // console.log("store", store.data);
    // this.animateView();
  },

  animateView() {
    wx.createSelectorQuery().select(`#a${store.data.settjitems.View_State}`).boundingClientRect(res => {
      if (res) {
        const animation = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease',
        });
        this.animation = animation.translateX(res.left).step();
        this.setData({ animationData: animation.export() });
      }
    }).exec();
  },

  changeType(e) {
    this.setData({ typeIndex: e.currentTarget.dataset.index });
    store.data.settjitems.View_State = this.data.typeIndex;
    this.animateView();
    this.fetchData();
  },

  onHide() {},

  onUnload() {},

  onPullDownRefresh() {
    this.fetchData();
    console.log("name", this.data.name);
    console.log("id", this.data.id);
    console.log("Begin_Year", this.data.Begin_Year);
    console.log("End_Year", this.data.End_Year);
    console.log("下拉刷新");
    console.log("000", this.data.Hospital);
    console.log("state1", this.data.state);
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 2000);
  },

  onReachBottom() {},

  onShareAppMessage() {}
});